namespace SimpleWebServices
{
    using System;
    using System.Globalization;
    using SimpleWebServices.Web.Mvc;

    public sealed class IsInRoleDecorationTest<T> : ITestExpectation
    {
        public string Roles
        {
            get;
            set;
        }

        public string Schemes
        {
            get;
            set;
        }

        public bool Check()
        {
            IsInRoleAttribute attribute = Attribute.GetCustomAttribute(typeof(T), typeof(IsInRoleAttribute), false) as IsInRoleAttribute;
            if (null == attribute)
            {
                throw new TestException(string.Format(CultureInfo.InvariantCulture, "{0} is not decorated with [IsInRole].", typeof(T).Name));
            }
            else if (this.Roles != attribute.Roles || this.Schemes != attribute.Schemes)
            {
                throw new TestException(string.Format(CultureInfo.InvariantCulture, "{0} is not decorated with [IsInRole(\"{1}\", \"{2}\")].", typeof(T).Name, this.Roles, this.Schemes));
            }

            return true;
        }
    }
}